package com.wlscale.roadsystem.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.easy.component.ibase.EasyBaseActivity;
import com.wlscale.roadsystem.wiget.AddCorrectNoteDialog;
import com.wlscale.roadsystem.wiget.CalibrationListAlertDialog;
import com.wlscale.roadsystem.wiget.ChoiceTimeAlertDialog;
import com.wlscale.roadsystem.wiget.NumInputAlertDialog;

public abstract class LZBaseActivity extends EasyBaseActivity {
    /**
     * 带输入框弹出框
     */
    private NumInputAlertDialog numInputAlertDialog;
    /**
     * 节点校准
     */
    private CalibrationListAlertDialog calibrationListAlertDialog;
    /**
     * 添加校准节点
     */
    private AddCorrectNoteDialog addCorrectNoteDialog;
    /**
     * 选择开始时间结束时间弹出框
     */
    private ChoiceTimeAlertDialog choiceTimeAlertDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    /**
     * 显示alert 样式的弹出框
     *
     * @param title
     * @param message
     * @param leftText
     * @param leftOnClickListener
     * @param rigthText
     * @param rigthOnClickListener
     */
    public void showNumInputAlert(CharSequence title, CharSequence message, CharSequence leftText, View.OnClickListener leftOnClickListener,
                                  CharSequence rigthText, View.OnClickListener rigthOnClickListener) {
        numInputAlertDialog = new NumInputAlertDialog.Builder().setContext(this).setTitle(title).setMessage(message)
                .setLeftText(leftText).setLeftOnClickListener(leftOnClickListener).setRigthText(rigthText)
                .setRigthOnClickListener(rigthOnClickListener).builder();
        numInputAlertDialog.show();
    }

    /**
     * 关闭alert 样式的弹出框
     */
    public void hideNumInputAlert() {
        if (null != numInputAlertDialog && numInputAlertDialog.isShowing()) {
            numInputAlertDialog.dismiss();
        }
        if (null != numInputAlertDialog) {
            numInputAlertDialog = null;
        }
    }

    /**
     * 显示alert 样式的弹出框
     *
     * @param title
     * @param leftText
     * @param leftOnClickListener
     */
    public void showSysCalAlert(CharSequence title, CharSequence leftText, View.OnClickListener leftOnClickListener) {
        calibrationListAlertDialog = new CalibrationListAlertDialog.Builder().setContext(this).setTitle(title)
                .setLeftText(leftText).setLeftOnClickListener(leftOnClickListener)
                .builder();
        calibrationListAlertDialog.show();
    }

    /**
     * 关闭alert 样式的弹出框
     */
    public void hideSysCalAlert() {
        if (null != calibrationListAlertDialog && calibrationListAlertDialog.isShowing()) {
            calibrationListAlertDialog.dismiss();
        }
        if (null != calibrationListAlertDialog) {
            calibrationListAlertDialog = null;
        }
    }

    /**
     * 显示alert 添加校准节点
     *
     * @param title
     * @param leftText
     * @param leftOnClickListener
     * @param rigthText
     * @param rigthOnClickListener
     */
    public void showAddCorrectNoteAlert(CharSequence title, CharSequence leftText, View.OnClickListener leftOnClickListener,
                                        CharSequence rigthText, View.OnClickListener rigthOnClickListener) {
        addCorrectNoteDialog = new AddCorrectNoteDialog.Builder().setContext(this).setTitle(title)
                .setLeftText(leftText).setLeftOnClickListener(leftOnClickListener).setRigthText(rigthText)
                .setRigthOnClickListener(rigthOnClickListener).builder();
        addCorrectNoteDialog.show();
    }

    /**
     * 关闭alert 样式的弹出框
     */
    public void hideAddCorrectNoteAlert() {
        if (null != addCorrectNoteDialog && addCorrectNoteDialog.isShowing()) {
            calibrationListAlertDialog.dismiss();
        }
        if (null != addCorrectNoteDialog) {
            addCorrectNoteDialog = null;
        }
    }
    /**
     *
     *选择开始时间结束时间弹出框
     * @param title
     * @param msg
     * @param leftText
     * @param rigthText
     * @param onClickLister
     */
    public void showChoiceTimeAlert(CharSequence title, String msg,CharSequence leftText,
                                    CharSequence rigthText, ChoiceTimeAlertDialog.OnClickLister onClickLister) {
        choiceTimeAlertDialog = new ChoiceTimeAlertDialog.Builder().setContext(this).setTitle(title).setMessage(msg)
                .setLeftText(leftText).setRigthText(rigthText)
                .setOnClickLister(onClickLister).builder();
        choiceTimeAlertDialog.show();
    }

    /**
     * 关闭alert 选择开始时间结束时间弹出框
     */
    public void hideChoiceTimeAlert() {
        if (null != choiceTimeAlertDialog && choiceTimeAlertDialog.isShowing()) {
            calibrationListAlertDialog.dismiss();
        }
        if (null != choiceTimeAlertDialog) {
            choiceTimeAlertDialog = null;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        hideNumInputAlert();
    }
}
